package dotest;

import java.util.*;

/**
 * 给一个字符类型的集合，请统计集合里元素出现的次数。
 */
public class FindLetter {

    public static void main(String[] args) {

        //初始化数组
        char[] arr = new char[]{'a', 'b', 'c', 'd','d','a','a','a','d','c'};

        //数组转集合
        ArrayList<Character> list = new ArrayList<Character>();
        for (char c : arr) {
            list.add(c);
        }

        //集合分类统计元素
        Map<Character, Integer> hashMap = new HashMap();
        for (Character c : list) {
            Integer t = hashMap.get(c)==null?0:hashMap.get(c);
            hashMap.put(c,t+1);
        }
        //打印结果
        for (Map.Entry<Character, Integer> keymap : hashMap.entrySet()) {
            System.out.println(keymap.getKey()+"："+keymap.getValue());
        }
    }
}
